require 'web_safe_filename/version'
require 'uri'

module WebSafeFilename
  class Scrubber

    def self.start
      new.traverse_directories
    end

    def scrub(file)
      File.rename(file, file.gsub(/[\x00\\:\*\?\"<>\|,#\$\@\%\!\^\~ ]/, '-'))
    end

    def traverse_directories(directory = Dir.pwd)
      Dir.chdir(directory) do
        Dir.glob('*').each do |entry|
          traverse_directories(entry) if File.directory?(entry)
          scrub(entry)
        end
      end
    end

  end
end